const constans = require('../../constans/constans.js');
const request = require('../../request.js');
const Toast = require('../../utils/Toast.js');
const LogUtils = require('../../utils/LogUtils.js');
const util = require('../../utils/util.js')
const app = getApp();


Page({
  data: {
    logs: [],
    height1: '',
    money:0,
    yue:0.00,
    btn_back:1,
    yuMoney:0.00,
    yesMoney: 0.00,
    coolMoney:0.00,
  },
  onLoad: function () {
    app.requestHeader = { 'Authorization': wx.getStorageSync('Authorization') }
    let that = this;
  
    // 获取系统信息
    wx.getSystemInfo({
      success: function (res) {
        // 获取可使用窗口宽度
        let clientHeight = res.windowHeight;
        // 获取可使用窗口高度
        let clientWidth = res.windowWidth;
        // 算出比例
        let ratio = 750 / clientWidth;
        // 算出高度(单位rpx)
        let height = clientHeight * ratio;
        // 设置高度
        that.setData({
          height1: height
        });
      }
    });
    request.get(
      constans.getProfile,
      {},
      function (data) {
        console.log(data)
       
        that.setData({
          yue: (data.data.data.remain / 100).toFixed(2),
          yuMoney: (data.data.data.cash / 100).toFixed(2),
          yesMoney: (data.data.data.remain / 100).toFixed(2),
          coolMoney: (data.data.data.freeze / 100).toFixed(2),
        });
        wx.setStorageSync('num_na', that.data.yue)
        if (data.data.data.remain/100 < 1) {
          that.setData({
            btn_back: 0.5,
          
          });
        }
      })
    
  },
  searchBox:function(e){
    var that=this;
    console.log(e.detail.formId)
    let re = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;

    console.log(re.test(e.detail.value.qian));
    if (re.test(e.detail.value.qian)){

    }else{
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: '提现金额小数点后面只能保留两位',
      })
      return;
    }
    console.log(parseFloat(this.data.yue), e.detail.value.qian)
    // if (e.detail.value.qian >= 1){
     
     
            request.get(
            constans.cash,
              { amount: parseFloat(e.detail.value.qian) * 100, formId:e.detail.formId},
            function (data) {
              console.log(data)
              Toast.loading("提现中...");
              if(data.data.code==0){
               
                var time=setInterval(function(){
                  request.get(
                    constans.checkCashProcessing,
                    { serial: data.data.data.serial },
                    function (data1) {
                      console.log(data1.data.code)
                      console.log(data1)
                      if (data1.data.code == -202) {
                        
                        
                      } else if (data1.data.code == 30000){
                        Toast.hideLoading();
                          wx.showModal({
                            title: '提示',
                            showCancel: false,
                            content: data1.data.message,
                            success:function(){
                              wx.setStorageSync('num_na', that.data.yue - e.detail.value.qian)
                              wx.navigateBack()
                            }
                          }) 
                        clearInterval(time);
                        console.log(data1.data.message)
                       
                      }else {
                        Toast.hideLoading();
                          wx.showModal({
                            title: '提示',
                            showCancel: false,
                            content: data1.data.message,
                            success: function () {
                              wx.setStorageSync('num_na', that.data.yue - e.detail.value.qian)
                              // wx.navigateBack()
                            }
                          }) 
                       
                        clearInterval(time);
                      }
                    })
                },2000)
               
                
              }else if(data.data.code==30000){
                Toast.hideLoading();
                  wx.showModal({
                    title: '提示',
                    showCancel: false,
                    content: data.data.message,
                  })
              }else{
                Toast.hideLoading();
                wx.showModal({
                  title: '提示',
                  showCancel: false,
                  content: data.data.message,
                })
              }
            })
      
    // }else{
     
    //   wx.showModal({
    //     title: '提示',
    //     showCancel: false,
    //     content: '提现金额不能小于1',
    //   })
    // }
    
  },
  detail_jilu: function () {
    wx.navigateTo({
      url: '../detail_jilu/detail_jilu'
    })
  },

})
function fun(){

}